package handle

import (
	"go_payment/dao"
	"log"
	"time"
)

func DoOrder() {
	ch := make(chan string)
	go OrderProducer(ch)
	go OrderConsumer(ch)
}

func OrderProducer(ch chan<- string) {
	t := time.NewTicker(1 * time.Second)
	for {
		orders := dao.RedoOrder()
		for _, v := range orders {
			ch <- v
		}
		<-t.C
	}
}

func OrderConsumer(ch <-chan string) {
	for ordsn := range ch {
		go func(ord string) {
			time.Sleep(3 * time.Second)
			log.Println(ord+"处理成功")
		}(ordsn)
	}
}
